<?php
/**
 * 主页面
 */
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>学生信息管理</title>
    <script>
        function delf(id) {
            if(confirm("确认删除？")){
                window.location='action.php?action=del&id='+id;
            }
        }
    </script>
</head>
<body>
    <?php include 'index.php';?>

    <table width="350" border="1" cellspacing="0">
        <tr>
            <td>ID</td>
            <td>姓名</td>
            <td>性别</td>
            <td>年龄</td>
            <td>班级</td>
            <td>操作</td>
        </tr>
        <?php
        include 'config.php';
        $sql="select * from stu";
        foreach($conn->query($sql) as $row){
            echo "<tr>";
            echo "<th>{$row['id']}</th>";
            echo "<th>{$row['name']}</th>";
            echo "<th>{$row['sex']}</th>";
            echo "<th>{$row['age']}</th>";
            echo "<th>{$row['class']}</th>";
            echo "<td>
                    <a href='edit.php?id={$row['id']}'>修改</a>
                    <a href='javascript:void(0);' onclick='delf({$row['id']})'>删除</a>
                    </td>";
            echo "</tr>";
        }
        ?>
    </table>
</body>
</html>
